/*---------------------------------------------------------
   Name: gamemode:ShowHelp( ply )
		Player pressed F1
		Send Help
---------------------------------------------------------*/
function GM:ShowHelp( ply )
	ply:ConCommand("gj_help")
end

/*---------------------------------------------------------
   Name: gamemode:ShowTeam( ply )
		Player pressed F2
		Weapons Drop
---------------------------------------------------------*/
function GM:ShowTeam( ply )
	if not ply:IsValid() or not ply:IsPlayer() then return false end
	Weap = ply:GetActiveWeapon()
	if not Weap or not Weap:IsValid() then return false end
	if not table.HasValue(self.CanNotDrop, Weap:GetClass()) then
		ply:DropWeapon(Weap)
	end
end

/*---------------------------------------------------------
   Name: gamemode:ShowSpare1( ply )
		Player pressed F3
		Set Player Team
---------------------------------------------------------*/
GM.GSwap = {}
GM.PSwap = {}

function GM:ShowSpare1( ply )
	if ply:Team() == TEAM_SPECTATOR then
		local G = team.NumPlayers(TEAM_GUARD) + team.NumPlayers(TEAM_GUARD_DEAD)
		local P = team.NumPlayers(TEAM_PRISONER) + team.NumPlayers(TEAM_PRISONER_DEAD)
		if P > 2*G then
			ply:SetTeam(TEAM_GUARD_DEAD)
		else
			ply:SetTeam(TEAM_PRISONER_DEAD)
		end
		if self.Round == ROUND_NO then
			self.Round = ROUND_START
			timer.Simple(25, function() self.Round = ROUND_PLAY end)
		end
		if self.Round == ROUND_START or G == 0 or P == 0 then
			if ply:Team() == TEAM_GUARD_DEAD then
				ply:SetTeam(TEAM_GUARD)
			elseif ply:Team() == TEAM_PRISONER_DEAD then
				ply:SetTeam(TEAM_PRISONER)
			end
			ply:Spawn()
			ply:SetCollisionGroup(5)
		end
		local rp = RecipientFilter()
		rp:AddPlayer(ply)
		umsg.Start("WishSwap", rp)
		umsg.Bool(false)
		umsg.End()
	else
		local rp = RecipientFilter()
		rp:AddPlayer(ply)
		umsg.Start("WishSwap", rp)
		if ply:Team() == TEAM_GUARD or ply:Team() == TEAM_GUARD_DEAD then
			if table.HasValue( self.GSwap, ply ) then
				for k,v in pairs(self.GSwap) do
					if v == ply then
						table.remove( self.GSwap, k )
					break end
				end
				umsg.Bool(false)
			else
				table.insert( self.GSwap, ply )
				umsg.Bool(true)
			end
		else
			if table.HasValue( self.PSwap, ply) then
				for k,v in pairs(self.PSwap) do
					if v == ply then
						table.remove( self.PSwap, k )
					break end
				end
				umsg.Bool(false)
			else
				table.insert( self.PSwap, ply )
				umsg.Bool(true)
			end
		end
		umsg.End()
	end
end

/*---------------------------------------------------------
   Name: gamemode:ShowSpare2( ply )
		Player pressed F4
---------------------------------------------------------*/
function GM:ShowSpare2( ply )
	if ply:Team() == TEAM_SPECTATOR then return end
	ply:SetTeam(TEAM_SPECTATOR)
	if table.HasValue( self.GSwap, ply ) then
		for k,v in pairs(self.GSwap) do
			if v == ply then
				table.remove( self.GSwap, k )
			break end
		end
	end
	if table.HasValue( self.PSwap, ply) then
		for k,v in pairs(self.PSwap) do
			if v == ply then
				table.remove( self.PSwap, k )
			break end
		end
	end
	local rp = RecipientFilter()
	rp:AddPlayer(ply)
	umsg.Start("WishSwap", rp)
	umsg.Bool(false)
	umsg.End()
	ply:Spawn()
end

/*---------------------------------------------------------
   Name: Some chat commands
---------------------------------------------------------*/
local function Say( ply, text, toall )
	local GM = gmod.GetGamemode()
	if string.sub(text, 1, 7) == "nextmap" then
		if not GM.NextMap then return end
		for _, pl in pairs(player.GetAll()) do
			pl:ChatPrint( "Nextmap: "..GM.NextMap )
		end
	end
	if string.sub(text, 1, 5) == "score" then
		for _, pl in pairs(player.GetAll()) do
			pl:ChatPrint( "Gardiens - "..team.GetScore(TEAM_GUARD).." | Prisonniers - "..team.GetScore(TEAM_PRISONER) )
		end
	end
end
hook.Add( "PlayerSay", "GJail_Say", Say )